//
//  STSloganModel.swift
//  SlowTrajectory
//
//  Created by iOS-Czz on 2023/10/23.
//

import UIKit
class STSloganViewModel{
    var dataSource = [STSloganModel]()
}
extension STSloganViewModel{
    func loadData(onSuccess: ((_ model: STSloganModel) ->Void)?){
        let dataHelper = STSloganModel.getUsingLKDBHelper()
        let sql = "select * from @t"
        let modelArr = dataHelper.search(withSQL: sql, to: STSloganModel.self) as! [STSloganModel]
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "yyyy-MM-dd"
        let sortedModels = modelArr.sorted { (model1, model2) -> Bool in
            guard let date1 = dateFormatter.date(from: model1.day!),
                  let date2 = dateFormatter.date(from: model2.day!) else {
                return false // 如果转换失败则直接返回 false
            }
            return date1 > date2
        }
        onSuccess?(sortedModels.first!)
    }
}

@objcMembers
class STSloganModel: STBaseModel,Codable {
    var day: String?
    var slogan: String?
    var bg: String?
    var isDefault = true
    override class func getTableName() -> String {
        return "ThermohygrometryTab"
    }
}

